from django.shortcuts import render
from django.http import HttpResponse
from django.conf import settings
import fitz


def index(request):
    # 这里是window文件路径是反斜杆，unix的系统下换回正斜杆即可
    pdf = fitz.open(settings.BASE_DIR + '\\app\static\pdf\ILNS.77.27.pdf')
    end_page = pdf[-1]
    print(end_page.rect.__dir__())
    print(end_page.rect[2])
    print(end_page.rect[3])

    rect = fitz.Rect(100, 100, 600, 600)
    with open(settings.BASE_DIR + '\\app\static\img\\label.png', 'rb') as img:
        stream = img.read()
        end_page.insertImage(rect, stream=stream)

    pdf.save(settings.BASE_DIR + '\\app\static\pdf-trans\ILNS.d.pdf')
    return HttpResponse("success")



